home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / YACC / landy.lex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-05  |  6.1 KB  |  248 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    Created by MM LEX (Macintosh) from:
  3.  *    "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  4.  *    Time: Mon Apr 16 19:59:27 1990
  5.  *    - for use with standard I/O
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <lex.h>
  10. #define LL16BIT SHORTINT
  11. extern SHORTINT _lmovb();
  12. extern struct lextab *_tabp;
  13. SHORTINT lexval;
  14. extern SHORTINT yyline;
  15. extern char lbuf[], *llend;
  16.  
  17. # line 9 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  18.  
  19. #include "stdlib.h"            /* Standard C conventions */
  20. #include "landy.yacc.h"        /* %term definitions from YACC, */
  21.                             /* i.e. -h output file */
  22. #ifdef    THINK_C
  23. #define    BOOLEAN    int            /* used on DECUS
  24. #endif
  25.  
  26. char yytext[256];        /* Communication with YACC actions */
  27. int yyival;                /*       "        "    "      "    */
  28. float yyfval;            /*       "        "    "      "    */
  29.  
  30. _Alextab(int __na__)        /* Action routine */
  31.     {
  32.     switch (__na__)
  33.         {
  34.  
  35.         case 0:
  36.  
  37. # line 25 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  38. gettoken(yytext, sizeof(yytext));
  39.                              printf("LEX/TCON: %s\n", yytext);
  40.                              return(TCON);
  41.             break;
  42.  
  43.         case 1:
  44.  
  45. # line 29 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  46. {
  47.             register char *p = yytext; BOOLEAN minus = FALSE;
  48.         gettoken(yytext, sizeof(yytext));
  49.         yyival = 0;
  50.         if(*p == '-') {
  51.             ++p;
  52.             minus = TRUE;
  53.         }
  54.         do {
  55.             if(*p != ',')
  56.             yyival = 10*yyival + (*p - '0');
  57.         } while(*++p);
  58.         if(minus) yyival = -yyival;
  59.         printf("LEX/ICON: %d\n", yyival);
  60.         return(ICON);
  61.         }
  62.             break;
  63.  
  64.         case 2:
  65.  
  66. # line 46 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  67. {
  68.         register char *p = yytext; long decimal = 0; BOOLEAN minus = FALSE;
  69.         gettoken(yytext, sizeof(yytext));
  70.         yyfval = 0.0;
  71.         if(*p == '-') {
  72.             ++p;
  73.             minus = TRUE;
  74.         }
  75.         do {
  76.             switch(*p) {
  77.             case ',':       break;
  78.             case '.':       decimal = 10; break;
  79.             default :       if(!decimal) {
  80.                     yyfval = 10. * (yyfval) + (*p - '0');
  81.                     break;
  82.                     } else {
  83.                     yyfval = yyfval + (*p - '0')/((float) decimal);
  84.                     decimal *= 10;
  85.                     break;
  86.                     }
  87.             }
  88.         } while (*++p);
  89.             if(minus) yyfval = -yyfval;
  90.             printf("LEX/FCON: %f\n", yyfval);
  91.             return(FCON);
  92.         }
  93.             break;
  94.  
  95.         case 3:
  96.  
  97. # line 73 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  98. return(LEXSKIP);
  99.             break;
  100.     }
  101.     return(LEXSKIP);
  102. }
  103.  
  104. # line 75 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  105.  
  106.  
  107. /*
  108.  * Hand-crafted lexgetc to give newline prompt.
  109.  */
  110.  
  111. lexgetc(){
  112.     static BOOLEAN newline = TRUE;
  113.     register int c;
  114.  
  115.     if(newline)
  116.         printf(">");
  117.  
  118.     if((c = getc(lexin)) == '\n')
  119.         newline = TRUE;
  120.     else
  121.         newline = FALSE;    
  122.  
  123.     return(c);
  124. }
  125.  
  126. LL16BIT _Flextab[] =
  127.    {
  128.     -1,   3,   3,   2,   2,   1,  -1,   0,
  129.      0,   0,  -1,
  130.    };
  131.  
  132. # line 95 "Psycho’s Stuff:Progs:YACCF:YACC Examples:LANDY FOLDER:landy.lxi"
  133.  
  134. #define    LLTYPE1    unsigned char
  135.  
  136. LLTYPE1 _Nlextab[] =
  137.    {
  138.     10,  10,  10,  10,  10,  10,  10,  10,
  139.     10,   1,   1,   2,   2,   1,  10,   2,
  140.     10,  10,  10,  10,  10,  10,  10,  10,
  141.     10,  10,  10,  10,  10,  10,  10,  10,
  142.      1,  10,   2,  10,   7,  10,  10,  10,
  143.     10,  10,  10,  10,  10,   6,   3,   6,
  144.      5,   5,   5,   5,   5,   5,   5,   5,
  145.      5,   5,  10,  10,  10,  10,  10,  10,
  146.     10,   7,   7,   7,   7,   7,   7,   7,
  147.      7,   7,   7,   7,   7,   7,   7,   7,
  148.      7,   7,   7,   7,   7,   7,   7,   7,
  149.      7,   7,   7,  10,  10,  10,  10,   7,
  150.     10,   7,   7,   7,   7,   7,   7,   7,
  151.      7,   7,   7,   7,   7,   7,   7,   7,
  152.      7,   7,   7,   7,   7,   7,   7,   7,
  153.      7,   7,   7,   4,   4,   4,   4,   4,
  154.      4,   4,   4,   4,   4,   3,   9,   5,
  155.      5,   5,   5,   5,   5,   5,   5,   5,
  156.      5,  10,   8,   8,   8,   8,   8,   8,
  157.      8,   8,   8,   8,  10,  10,  10,  10,
  158.     10,  10,  10,   9,   9,   9,   9,   9,
  159.      9,   9,   9,   9,   9,   9,   9,   9,
  160.      9,   9,   9,   9,   9,   9,   9,   9,
  161.      9,   9,   9,   9,   9,  10,  10,  10,
  162.     10,   9,  10,   9,   9,   9,   9,   9,
  163.      9,   9,   9,   9,   9,   9,   9,   9,
  164.      9,   9,   9,   9,   9,   9,   9,   9,
  165.      9,   9,   9,   9,   9,
  166.    };
  167.  
  168. LLTYPE1 _Clextab[] =
  169.    {
  170.     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
  171.     -1,   0,   0,   1,   1,   0,  -1,   1,
  172.     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
  173.     -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
  174.      0,  -1,   1,  -1,   0,  -1,  -1,  -1,
  175.     -1,  -1,  -1,  -1,  -1,   0,   0,   6,
  176.      0,   0,   0,   0,   0,   0,   0,   0,
  177.      0,   0,  -1,  -1,  -1,  -1,  -1,  -1,
  178.     -1,   0,   0,   0,   0,   0,   0,   0,
  179.      0,   0,   0,   0,   0,   0,   0,   0,
  180.      0,   0,   0,   0,   0,   0,   0,   0,
  181.      0,   0,   0,  -1,  -1,  -1,  -1,   0,
  182.     -1,   0,   0,   0,   0,   0,   0,   0,
  183.      0,   0,   0,   0,   0,   0,   0,   0,
  184.      0,   0,   0,   0,   0,   0,   0,   0,
  185.      0,   0,   0,   3,   3,   3,   3,   3,
  186.      3,   3,   3,   3,   3,   5,   7,   5,
  187.      5,   5,   5,   5,   5,   5,   5,   5,
  188.      5,  -1,   7,   7,   7,   7,   7,   7,
  189.      7,   7,   7,   7,  -1,  -1,  -1,  -1,
  190.     -1,  -1,  -1,   7,   7,   7,   7,   7,
  191.      7,   7,   7,   7,   7,   7,   7,   7,
  192.      7,   7,   7,   7,   7,   7,   7,   7,
  193.      7,   7,   7,   7,   7,  -1,  -1,  -1,
  194.     -1,   7,  -1,   7,   7,   7,   7,   7,
  195.      7,   7,   7,   7,   7,   7,   7,   7,
  196.      7,   7,   7,   7,   7,   7,   7,   7,
  197.      7,   7,   7,   7,   7,
  198.    };
  199.  
  200. LLTYPE1 _Dlextab[] =
  201.    {
  202.     10,  10,   1,  10,   3,  10,   5,  10,
  203.      7,   7,
  204.    };
  205.  
  206. LL16BIT _Blextab[] =
  207.    {
  208.      0,   2,   0,  75,   0,  87,   2,  98,
  209.      0,   0,   0,
  210.    };
  211.  
  212. struct lextab lextab =    {
  213.             10,        /* Highest state */
  214.             _Dlextab,    /* --> "Default state" table */
  215.             _Nlextab,    /* --> "Next state" table */
  216.             _Clextab,    /* --> "Check value" table */
  217.             _Blextab,    /* --> "Base" table */
  218.             220,        /* Index of last entry in "next" */
  219.             _lmovb,        /* --> Byte-SHORTINT move routine */
  220.             _Flextab,    /* --> "Final state" table */
  221.             _Alextab,    /* --> Action routine */
  222.  
  223.             NULL,       /* Look-ahead vector */
  224.             0,        /* No Ignore class */
  225.             0,        /* No Break class */
  226.             0,        /* No Illegal class */
  227.             };
  228.  
  229. #ifndef    LLBUFSIZE
  230. #define    LLBUFSIZE 256
  231. #endif
  232.  
  233.  
  234. /* Standard I/O selected */
  235. FILE * lexin;
  236.  
  237. llstin()
  238.     {
  239.     if(lexin == NULL)
  240.         lexin = stdin;
  241.     if(_tabp == NULL)
  242.         lexswitch(&lextab);
  243.     llbuf = calloc(LLBUFSIZE,sizeof(char));
  244.     llbufsize = LLBUFSIZE;
  245.     llinit();
  246.     }
  247.  
  248.